! Configuration File for keepalived

global_defs {
    notification_email {
        root@localhost
    }
    notification_email_from keepalived@localhost
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id {{ keepalived_router_id | d("keepalived-node1") }}
    vrrp_mcast_group4 {{ keepalived_vrrp_mcast_group4 | d("224.0.0.18") }}
}

{% for inst in keepalived_vrrp_instance %}
vrrp_instance {{ inst.name | d('V1_1') }} {
    state {{ inst.state | d('MASTER') }}
    interface {{ inst.interface | d(ansible_default_ipv4.interface) }}
    virtual_router_id {{ inst.virtual_router_id | d('26') }}
    priority {% if inst.state == 'MASTER' %}{{ keepalived_priority | d('100') }}{% else %}{{ keepalived_priority | d('98') }}{% endif %}

    advert_int 1
    authentication {
        auth_type PASS
        auth_pass {{ inst.auth_pass | d('lework66') }}
    }
{% if inst.unicast_peer is defined %}
    unicast_src_ip {{ ansible_default_ipv4.address }}
    unicast_peer {              
        {{ inst.unicast_peer }}
    }
{% endif %}
    virtual_ipaddress {
        {{ inst.vip }}
    }
    {{ inst.extra | d('') }}
}

{% endfor %}
{% if keepalived_virtual_server %}
{% for vser in keepalived_virtual_server %}
virtual_server {{ vser.virtual_server }} {
    delay_loop {{ vser.delay_loop | d('6') }}
    lb_algo {{ vser.lb_algo | d('wrr') }}
    lb_kind {{ vser.lb_kind | d('NAT') }}
    persistence_timeout {{ vser.persistence_timeout | d('50') }}
    protocol {{ vser.protocol | d('TCP') }}

{% for rser in vser.real_server %}
    real_server {{ rser.server }} {
        weight {{ rser.weight | d('1') }}
{% if vser.protocol is undefined or vser.protocol == 'TCP'%}
        TCP_CHECK {
          connect_port {{ rser.tcp_check['connect_port'] | d('80') }}  
          connect_timeout {{ rser.tcp_check['connect_timeout'] | d('10') }}    
          nb_get_retry {{ rser.tcp_check['nb_get_retry'] | d('3') }}  
          delay_before_retry {{ rser.tcp_check['delay_before_retry'] | d('3') }}  
        }
{% endif %}
{% if rser.extra is defined %}
        {{ rser.extra | d('') }}
{% endif %}
    }
{% endfor %}
{% if vser.extra is defined %}
    {{ vser.extra | d('') }}
{% endif %}
}

{% endfor %}
{% endif %}
{{ keepalived_conf_extra }}
